<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Verify signature</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-sign.html">openssl_sign</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.openssl-x509-check-private-key.html">openssl_x509_check_private_key</a></div>
 <div class="up"><a href="ref.openssl.html">OpenSSL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.openssl-verify" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_verify</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">openssl_verify</span> &mdash; <span class="dc-title">Verify signature</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-verify-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>openssl_verify</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$signature</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$pub_key_id</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$signature_alg</code><span class="initializer"> = OPENSSL_ALGO_SHA1</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>openssl_verify()</strong></span> verifies that the
   <em><code class="parameter">signature</code></em> is correct for the specified
   <em><code class="parameter">data</code></em> using the public key associated with
   <em><code class="parameter">pub_key_id</code></em>. This must be the public key
   corresponding to the private key used for signing.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-verify-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">data</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">signature</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">pub_key_id</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">signature_alg</code></em></dt>

     <dd>

      <p class="para">
       For more information see the list of <a href="openssl.signature-algos.html" class="link">Signature Algorithms</a>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-verify-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns 1 if the signature is correct, 0 if it is incorrect, and
   -1 on error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.openssl-verify-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.2.0</td>
       <td>
        The <em><code class="parameter">signature_alg</code></em> parameter was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-verify-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-845">
    <p><strong>Example #1 <span class="function"><strong>openssl_verify()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$data&nbsp;and&nbsp;$signature&nbsp;are&nbsp;assumed&nbsp;to&nbsp;contain&nbsp;the&nbsp;data&nbsp;and&nbsp;the&nbsp;signature<br /><br />//&nbsp;fetch&nbsp;public&nbsp;key&nbsp;from&nbsp;certificate&nbsp;and&nbsp;ready&nbsp;it<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/src/openssl-0.9.6/demos/sign/cert.pem"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$cert&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8192</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pubkeyid&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_get_publickey</span><span style="color: #007700">(</span><span style="color: #0000BB">$cert</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;state&nbsp;whether&nbsp;signature&nbsp;is&nbsp;okay&nbsp;or&nbsp;not<br /></span><span style="color: #0000BB">$ok&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_verify</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$signature</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$pubkeyid</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$ok&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"good"</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;(</span><span style="color: #0000BB">$ok&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"bad"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"ugly,&nbsp;error&nbsp;checking&nbsp;signature"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #FF8000">//&nbsp;free&nbsp;the&nbsp;key&nbsp;from&nbsp;memory<br /></span><span style="color: #0000BB">openssl_free_key</span><span style="color: #007700">(</span><span style="color: #0000BB">$pubkeyid</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-verify-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.openssl-sign.html" class="function" rel="rdfs-seeAlso">openssl_sign()</a> - Generate signature</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-sign.html">openssl_sign</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.openssl-x509-check-private-key.html">openssl_x509_check_private_key</a></div>
 <div class="up"><a href="ref.openssl.html">OpenSSL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
